#include <interface\timer.h>

timer::timer(): running( false ),
                ended( false ),
                startTime( 0 ),
                duration( 0 )
{}
timer::~timer(){}

void timer::setDuration(clock_t inTime){
    duration = inTime;
}
void timer::start(){
    running = true;
    startTime = clock();
}
void timer::reset(){
    running = false;
    ended = false;
    startTime = 0;
}

clock_t timer::getDuration(){
    return duration;
}
clock_t timer::getCurrentTime(){
    if( !running ) return 0;
    return clock() - startTime;
}
float timer::getProgress(){
    float out = (float)(clock()-startTime)/(float)(duration);
    if( out < 0 ) out = 0;
    if( out > 1 ) out = 1;
    return out;
}

bool timer::isEnded(){
    if( ended ) return true;
    if( !duration ) return false;
    if( (startTime + duration) <= clock() ) return  ended = true;
    return false;
}

bool timer::isRunning(){
    return running;
}
